//
//  KLObjectTestCase.m
//  Koala
//
//  Created by Tommy on 14-8-29.
//  Copyright (c) 2014年 com.koala. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "KLObject.h"


@interface KLObjectTestItem : KLObject
@property(nonatomic)CGFloat floatNum;
@property(nonatomic)NSString *desc;

@end

@implementation KLObjectTestItem



@end

@interface KLObjectTest : KLObject
@property(nonatomic)NSInteger intNum;
@property(nonatomic)NSString *string;
@property(nonatomic)NSArray *itemArray;


@end
@implementation KLObjectTest

- (NSString*)keyClassName:(NSString *)key{
    if([key isEqualToString:@"itemList"]){
        return @"KLObjectTestItem";
    }
    
    return [super keyClassName:key];
}

- (NSString*)key:(NSString *)propertyName{
    if([propertyName isEqualToString:@"itemArray"])
        return @"itemList";
    return [super key:propertyName];
}


@end

@interface KLObjectTestCase : XCTestCase

@end

@implementation KLObjectTestCase

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testKLObject{
    NSDictionary * dict =  @{@"intNum":@(1),@"string":@"hello",@"itemList":@[@{@"floatNum":@(0.5),@"desc":@("first")},@{@"floatNum":@(7.5),@"desc":@("second")}]};
    
    KLObjectTest *obj = [KLObjectTest objectWithJson:dict withClassName:@"KLObjectTest"];
    NSLog(@"obj:%@",obj);
    
    NSDictionary * postDict = [obj buildDict];
    NSLog(@"dict:%@",postDict);
    
    
    KLObjectTest *obj2 = [KLObjectTest objectWithJson:dict withClassName:@"KLObjectTest"];
    NSLog(@"obj2:%@",obj2);
    
    
    NSData *objData = [obj archivedData];//[NSKeyedArchiver archivedDataWithRootObject:obj];
    
    KLObjectTest *obj3 = [KLObjectTest unarchiveObject:objData]; //[NSKeyedUnarchiver unarchiveObjectWithData:objData];
    
    NSLog(@"obj3:%@",obj3);
    
    KLObjectTest *obj4 = [obj3 copy];
    
    
    NSLog(@"obj4:%@",obj4);
    
}

@end
